const mood=require("../models/mood")

//获取所有博客信息
exports.getboke=async function (){
    const result=await mood.findAll()
    return result;
}

// 分页查询
const {
    Op, where
} = require("sequelize");
const req = require("express/lib/request");
// const Class = require("../models/Class")
exports.getfenye= async function (page = 1, limit = 10, keywords = "") {
    const where = {
        [Op.or]: [{
                name: {
                    [Op.like]: `%${keywords}%`
                }
            },
        ]
    };
    const result = await mood.findAndCountAll({
        offset: (page - 1) * limit,
        limit: +limit,
        where
    })
    return JSON.parse(JSON.stringify(result))
}
//查
exports.getIdfind = async function (page = 1, limit = 10, id) {
    const result = await mood.findAndCountAll({
        offset: (page - 1) * limit,
        limit: +limit,
        where: {
            id
        }
    })
    return JSON.parse(JSON.stringify(result))
}
//添加修改
exports.updateBoke = async function (id, obj) {
    return await mood.update(obj, {
        where: {
            id
        }
    });
}

const pl=require("../models/pl")
exports.getPl = async function (page = 1, limit = 10) {
    const result = await mood.findAndCountAll({
        // attributes: ["id", "name", "sex", "birthday"], //只看部分字段
        include: [pl], //关联表,包含关系
        offset: (page - 1) * limit,
        limit: +limit,
    })
    return JSON.parse(JSON.stringify(result))
}

